import {useEffect, useState} from 'react'

export default function useDetailHook({func,searchFunc}) {
  const [ loading, setLoading ] = useState(false)

  const [ detailData, setDetailData ] = useState({})

  const initDetailData = async () => {
    setLoading(true)
    const result = await func()
    if (result) {
      setDetailData(result)
    }
    setLoading(false)
  }

  const onSearch = () => {
    initDetailData()
  }

  searchFunc && searchFunc(onSearch)

  useEffect(() => {
    initDetailData()
  }, [])

  return {detailData, loading}
}
